package com.huluobo.high3videoproject.mvp.video.presenter;

import com.huluobo.base.view.BasePresenter;
import com.huluobo.high3videoproject.bean.VideoBeanResult;
import com.huluobo.high3videoproject.mvp.video.model.VideoModel;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class VideoPresenter extends BasePresenter<VideoContract.View> implements VideoContract.Presenter {
    private VideoModel videoModel = new VideoModel();

    @Override
    public void getVideoList(int page, int size) {
        videoModel.getVideoList(page, size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        compositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(VideoBeanResult videoBeanResult) {
                        if (isAttach()) {
                            getView().onGetVideoListSuccess(videoBeanResult);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (isAttach()) {
                            getView().onGetVideoListFailed(e.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
